/*
* 2014-9-17 上午11:02:02
* 吴健 HQ01U8435
*/

package com.hunteron.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ConnectionHandler {

	private Connection connection = null;
	private Statement statement = null;
	private ResultSet resultSet = null;
	public ConnectionHandler() throws SQLException {
		connection = JDBCConnector.getConnection();
		statement = connection.createStatement();
	}

    public ConnectionHandler(String dbName) throws SQLException {
        connection = JDBCConnector.getConnection(dbName);
        statement = connection.createStatement();
    }
	
	public ResultSet executeSql(String sql) throws SQLException {
		resultSet = statement.executeQuery(sql);
		return resultSet;
	}
	
	public int executeUpdate(String sql) throws SQLException {
		return statement.executeUpdate(sql);
	}
	
	public void close() {
		try {
			if(resultSet != null) {
				resultSet.close();
			}
		} catch (Exception e) {
		}
		if(statement != null) {
			try {
				statement.close();
			} catch (SQLException e) {
			}
		}
		if(connection != null) {
			try {
				connection.close();
			} catch (SQLException e) {
			}
		}
	}
}
